<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>RequestIdleCallback Example</title>
  </head>
  <body>
    <h1 id="updateMe">等待更新...</h1>

    <script>
      function updateTextContent() {
        const targetElement = document.getElementById("updateMe");
        targetElement.textContent = "文本内容已成功在空闲周期内更新！";
      }

      if ("requestIdleCallback" in window) {
        window.requestIdleCallback(updateTextContent);
      } else {
        console.log("requestIdleCallback is not supported in this browser.");
        // 如果浏览器不支持 requestIdleCallback，可以考虑使用其他策略（如setTimeout）来更新文本
      }
    </script>
  </body>
</html>
